Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

316
Views
Doxygen and "self" keyword on PHP documentation

I'm tryin to document a my PHP library with doxygen, but I cannot configure it to let recognize the correct usage of member function of my class, using the keyword "self". For instance the following code:

Class myclass{
    public static function myfunc1(){
      return 10; }
    public static function myfunc2(){
      return self::myfunc1(); }
}

is not correctly documented. Doxygen maps the two funcions, but when it refer to the internal or external call to these function, it doesn't take in account the myfunc1 called by myfunc2.

My workaround at the moment is to changed the code as follows:

Class myclass{
    public static function myfunc1(){
      return 10; }
    public static function myfunc2(){
      return myclass::myfunc1(); }
}

In this case doxygen refers correctly to the usage of myfunc1 related to myfunc2. Of course I don't like very much this solution. How can I solve this issue? thank you very much

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Doxygen provides input filter option, which enables us to change the source code at the time of documentation creation. For e.g. It gives us ability to intercept the code and change the code self::myfunc1 to myclass::myfunc1 on fly, which Doxygen understands. It does not change the actual source code in any way.

I have created a filter based on code from Doxygen PHP Filters with some modifications, which can do the changes for you.

Please create a file /path/to/selfFilter.php and put the code inside it:

<?php
//Create file /path/to/selfFilter.php

$source = file_get_contents($argv[1]);
$tokens = token_get_all($source);
$classes = array();
foreach($tokens as $key => $token)
{
    if($token[0] == T_CLASS)
        $classes[] = $tokens[$key+2][1];
}
if(!empty($classes))
{
    list($source, $tail) = explode('class ' . $classes[0], $source, 2);
    $class_code = '';
    for($i = 1; $i < count($classes); $i++)
    {
        list($class_code, $tail) = explode('class ' . $classes[$i], $tail, 2);
        $class_code = preg_replace('#\bself::#', $classes[$i-1].'::', $class_code);
        $source .= 'class ' . $classes[$i-1] . $class_code;
    }
    $class_code = preg_replace('#\bself::#', $classes[count($classes)-1].'::', $tail);
    $source .= 'class ' . $classes[count($classes)-1] . $class_code;

}

echo $source;

Update the following options in your doxygen config file.

INPUT_FILTER           = "php /path/to/selfFilter.php"
FILTER_PATTERNS        = 
FILTER_SOURCE_FILES    = YES
FILTER_SOURCE_PATTERNS =

Please make sure that the /path/to/selfFilter.php is executable and php is available on the path, otherwise use the full php path

INPUT_FILTER           = /usr/bin/php /path/to/selfFilter.php

If you run the Doxygen now it should work. Please let me know if you have any issues.

Note: The keyword 'class' should be defined in lower case for the above filters to work.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!